import os.path
from wxpyview.ui.core.common.exceptions import *
from wxpyview.ui.core.dataprovider.ExternalDataProvider import *
from wxpyview.ui.core.dataprovider.InternalDataProvider import *
from wxpyview.ui.core.DOM import *
from wxpyview.ui.core.MetaWidgetEntry import *
from wxpyview.ui.core.MetaWidgetTree import *
from wxpyview.ui.core.WidgetGenerator import *

class BaseUIGenerator:
    def __init__(self):
        self.dom_tree = None
        self.widget_generator = None
    
    def parse(self, resource_path):
        if not os.path.exists(resource_path):
            raise UnknownResource(resource_path)
    
    def createRealWidgets(self):
        self.widget_generator = WidgetGenerator()

    def _aCreateRealWidgets(self, meta_widget):
        child_meta_widgets = meta_widget.getChildMetaWidgets()

        for meta_widget in child_meta_widgets:
            widget_object = self.widget_generator.generate(meta_widget)
            self._aCreateRealWidgets(meta_widget)
            # post processing
            self.widget_generator.finalize(meta_widget)